package com.efast.dmom.equipment.statemach.handler.maintain;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.efast.cafe.commponent.statemach.annotation.StatemachHandle;
import com.efast.cafe.commponent.statemach.base.HandleBaseProcessorService;
import com.efast.cafe.commponent.statemach.bean.TaskParamBean;
import com.efast.cafe.commponent.statemach.service.IStatemMachAdapterService;
import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.equipment.entity.EquipRepairOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * zch
 * 
 */
@Component
@StatemachHandle(handleName = "repair", configId = 1020, entityName = "equip_repair_order")
public class EquipMaintainRepairHandler implements HandleBaseProcessorService<EquipRepairOrder> {

	@Autowired
	private IStatemMachAdapterService statemMachAdapterService;

	@Override
	public void process(JSONObject taskBean, EquipRepairOrder orderEntity, Map<String, JSONObject> extFormDataJson) {

		TaskParamBean taskParam = new TaskParamBean();
		taskParam.setConfId(Long.valueOf(1010));
		
		JSONObject orderDetails = new JSONObject();
		
		//TODO DBEntityConstants
		orderDetails.put("reason", orderEntity.getReason());
		orderDetails.put("repairCode", orderEntity.getRepairCode());
		orderDetails.put("equipId", orderEntity.getEquipId());
		orderDetails.put("equipCode", orderEntity.getEquipCode());
		orderDetails.put("equipName", orderEntity.getEquipName());
		orderDetails.put("priority", orderEntity.getPriority());
		orderDetails.put("createUser", SpringWebUtils.getRequestUser());
		orderDetails.put("lastUpdateUser", SpringWebUtils.getRequestUser());
		orderDetails.put("companyCode", SpringWebUtils.getRequestCompany());
		
		JSONObject repairOrderObj = new JSONObject();
		repairOrderObj.put("equip_repair_order", orderDetails);
		
		JSONObject extFormDataObj = new JSONObject();
		extFormDataObj.put("extFormData", repairOrderObj);
		
		taskParam.setParajson(JSONObject.toJSONString(extFormDataObj, SerializerFeature.WriteMapNullValue));

		try {
			statemMachAdapterService.beginAdapter(taskParam, "doSubmit");

		} catch (Exception e) {

		}
	}

}
